package me.jiatao.taobaotools.utils;

import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.Toast;


/***
 * 显示帮助类
 *
 * @author Jiatao
 */
public class ShowMessageUtils {
    public static String TAG = "******com.uuuo.uosdk******";
    private static Toast toast;

    public static void show(Context ctx, String msg) {
        show(ctx, msg, Toast.LENGTH_SHORT);
    }

    public static void showLongTime(Context ctx, String msg) {
        show(ctx, msg, Toast.LENGTH_LONG);
    }

    public static void showLongTime(Context ctx, int msgId) {
        show(ctx, msgId, Toast.LENGTH_LONG);
    }

    public static void show(Context ctx, String msg, int duration) {
//        toast.cancel();
        if (toast == null) {
            toast = Toast.makeText(ctx, msg, duration);
        }
        toast.setText(msg);
        toast.show();
    }

    public static void show(Context ctx, int msgId, int duration) {
        show(ctx, ctx.getResources().getString(msgId), duration);
    }

    public static void show(Context ctx, int msgId) {
        show(ctx, msgId, Toast.LENGTH_SHORT);
    }

    public static void hide() {
        if (toast != null) {
            toast.cancel();
        }
    }

    public static void showWithImg(Context ctx, int imgId) {

        Toast toast = Toast.makeText(ctx, "", Toast.LENGTH_LONG);

        toast.setGravity(Gravity.CENTER, 0, 0);

        ImageView view = new ImageView(ctx);
        view.setImageResource(imgId);

        toast.setView(view);
        toast.show();
    }

    public static void showInLogCat(String message) {
        showInLogCat(TAG, message);
    }

    public static void showInLogCat(String tag, String message) {
        Log.i(tag, message);
    }

    public static void showReleaseLogCat(String message) {
        showReleaseLogCat(TAG, message);
    }

    public static void showReleaseLogCat(String tag, String message) {
        Log.i(tag, message);
    }
}
